home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include "askrunlevel.h"
- #include "../misc/misc.h"
- #include "../paths.h"
- #include "askrunlevel.m"
-
- static HELP_FILE help_boot_log (HELP_ASKRUN,"bootlog");
-
- static CONFIG_FILE f_boot_log (VAR_ADM_BOOT_LOG
- ,help_boot_log
- ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED);
-
- static const char key[]="#########";
- static const int sizekey = 9;
- /*
- Store the boot message in /var/adm/boot.log
- */
- void boot_save2log()
- {
- /* #Specification: askrunlevel / boot log
- At each boot, askrunlevel grab the log (/proc/kmsg) and
- stores it in /var/adm/boot.log. askrunlevel can present
- these logs to the user later.
-
- For this reason, you won't find this information in
- /var/adm/messages like a normal linux.
- */
- FILE *fout = f_boot_log.fopen ("a");
- if (fout != NULL){
- {
- time_t tim = time(NULL);
- const char *datestr = asctime(localtime(&tim));
- fprintf (fout,"%s %s\n",key,datestr);
- }
- int fin = open ("/proc/kmsg",O_RDONLY|O_NDELAY);
- if (fin != -1){
- fd_set set;
- FD_ZERO (&set);
- FD_SET (fin,&set);
- struct timeval timeout;
- timeout.tv_usec = timeout.tv_sec = 0;
- if (select(fin+1,&set,NULL,NULL,&timeout)>0){
- char buf[5000];
- int nb = read (fin,buf,sizeof(buf)-1);
- if (nb >= 0){
- buf[nb] = '\0';
- if (fout != NULL){
- fputs (buf,fout);
- }
- }
- }
- close (fin);
- }
- fclose (fout);
- }
- }
-
- /*
- Locate all boot intro or a specific log in the log file
-
- if choice == -1, get all intro
- if choice != -1. get one log
- */
- static int boot_getlist(SSTRINGS &lst, int choice)
- {
- FILE *fin = f_boot_log.fopen ("r");
- if (fin != NULL){
- char buf[300];
- int collect = 0;
- int nbboot = 0;
- while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
- strip_end (buf);
- if (strncmp(buf,key,sizekey)==0){
- if (choice == -1){
- lst.add (new SSTRING (buf+sizekey+1));
- }else if (choice == nbboot){
- collect = 1;
- }else{
- collect = 0;
- }
- nbboot++;
- }else if (collect){
- lst.add (new SSTRING (buf));
- }
- }
- fclose (fin);
- }
- return lst.getnb();
- }
-
-
- /*
- Present the logs of the last boots
- */
- void boot_showlog ()
- {
- SSTRINGS lst;
- int nb = boot_getlist(lst,-1);
- if (nb == 0){
- xconf_error (MSG_U(E_NOLOG,"No log available"));
- }else{
- int choice = nb - 1;
- while (1){
- const char **menul = (const char **)malloc((lst.getnb()*2+1)
- * sizeof(char*));
- int ii = 0;
- for (int i=0; i<lst.getnb(); i++){
- SSTRING *st = lst.getitem(i);
- menul[ii++] = " ";
- menul[ii++] = st->get();
- }
- menul[ii] = NULL;
- MENU_STATUS code = xconf_menu (MSG_U(T_BOOTLOG,"boot log")
- ,MSG_U(I_BOOTLOG
- ,"These are the recording of the previous\n"
- "boot of this machine")
- ,help_boot_log
- ,menul
- ,choice);
- if (code == MENU_OK){
- SSTRINGS onelog;
- if (boot_getlist(onelog,choice)==0){
- xconf_error (MSG_U(E_EMPTYLOG,"Empty log"));
- }else{
- dialog_textbox (lst.getitem(choice)->get(),onelog);
- }
- }else{
- break;
- }
- }
- }
- }
-
-